import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { useTabStore } from '@/stores/tab'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      redirect: '/fsdy/film',
      children: [
        {
          path: 'htgl',
          name: 'htgl',
          redirect: '/htgl/sjfx',
          children: [
            {
              path: 'sjfx',
              name: 'sjfx',
              component: () => import('../views/htgl/sjfx.vue'),
              meta: {
                title: '数据分析',
                parent: '后台管理'
              }
            }
          ]
        },
        {
          path: 'fsdy',
          name: 'fsdy',
          redirect: '/fsdy/film',
          children: [
            {
              path: 'cinema',
              name: 'cinema',
              component: () => import('../views/fsdy/Cinema.vue'),
              meta: {
                title: '影院管理',
                parent: '锋神电影'
              }
            },
            {
              path: 'film',
              name: 'film',
              component: () => import('../views/fsdy/Film.vue'),
              meta: {
                title: '电影管理',
                parent: '锋神电影'
              }
            },
            {
              path: 'music',
              name: 'music',
              component: () => import('../views/fsdy/Music.vue'),
              meta: {
                title: '音乐管理',
                parent: '锋神电影'
              }
            },
          ]
        },
        {
          path: '/user',
          name: 'yhgl',
          children: [
            {
              path: '',
              name: 'yhlb',
              component: () => import('../views/user/user.vue'),
              meta: {
                title: '用户列表',
                parent: '用户管理'
              }
            },
            {
              path: 'create',
              name: 'yhcj',
              component: () => import('../views/user/create.vue'),
              meta: {
                title: '用户创建',
                parent: '用户管理'
              }
            },
          ]
        },
        {
          path: '/role',
          name: 'jsgl',
          children: [
            {
              path: '',
              name: 'jslb',
              component: () => import('../views/role/role.vue'),
              meta: {
                title: '角色列表',
                parent: '角色管理'
              }
            },
            {
              path: 'create',
              name: 'jscj',
              component: () => import('../views/role/create.vue'),
              meta: {
                title: '角色创建',
                parent: '角色管理'
              }
            },
          ]
        },
        {
          path: '/auth',
          name: 'qxgl',
          children: [
            {
              path: '',
              name: 'qxlb',
              component: () => import('../views/qxgl/qxlb.vue'),
              meta: {
                title: '权限列表',
                parent: '权限管理'
              }
            },
            {
              path: 'create',
              name: 'qxcj',
              component: () => import('../views/qxgl/create.vue'),
              meta: {
                title: '权限创建',
                parent: '权限管理'
              }
            },
          ]
        },
      ]
    },
    {
      path: '/sjksh',
      name: 'sjksh',
      component: () => import('../views/htgl/sjksh.vue'),
      meta: {
        title: '数据可视化',
        parent: '后台管理'
      }
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
    },

  ],
})

router.beforeEach((to, from) => {
  // console.log('to:' + JSON.stringify(to));

  const tabStore = useTabStore()
  // console.log(to.path + to.meta.title)
  tabStore.add({
    label: to.meta.title,
    path: to.path
  })
  document.title = to.meta.title
  return true
})

export default router
